package com.ruoyi.tester.login;

import com.ruoyi.tester.domain.TesterLoginConfig;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author SongJun
 * @description TODO:
 * @date 2022/4/18 13:28
 */
@Service
public class LoginHandlerContainer {
    private static Map<String, Login> container = new ConcurrentHashMap<>();

    public static Login getLoginHandler(String loginType){
        return container.get(loginType);
    }

    public static Login getLoginHandler(Long loginConfigId){
        if(loginConfigId != null) {
            TesterLoginConfig loginBaseInfo = LoginCache.getLoginBaseInfo(loginConfigId);
            if (loginBaseInfo != null) {
                return container.get(loginBaseInfo.getLoginType());
            }
        }
        return null;
    }

    public static void register(String loginType, Login handler){
        container.put(loginType, handler);
    }
}
